package com.itboye.boyeshoping.presenter;

import com.itboye.boyeshoping.inf.IShoping;
import com.itboye.boyeshoping.response.ShopResponse;
import com.itboye.boyeshoping.util.volley.BasePresenter;
import com.itboye.boyeshoping.util.volley.ICompleteListener;
import com.itboye.boyeshoping.util.volley.ResultEntity;


import java.util.Observer;

/**
 * Created by Administrator on 2018/7/27 0027.
 */

public class ShopPresenter extends BasePresenter implements IShoping {

    // 淘宝登录
    public static final String By_UserTbAccount_registerTb_success = ShopPresenter.class.getName()
            + "_By_UserTbAccount_registerTb_success";
    public static final String By_UserTbAccount_registerTb_fail = ShopPresenter.class.getName()
            + "_By_UserTbAccount_registerTb_fail";

    // 发送验证码
    public static final String By_SecurityCode_send_success = ShopPresenter.class.getName()
            + "_By_SecurityCode_send_success";
    public static final String By_SecurityCode_send_fail = ShopPresenter.class.getName()
            + "_By_SecurityCode_send_fail";
    // 验证验证码
    public static final String By_SecurityCode_verify_success = ShopPresenter.class.getName()
            + "_By_SecurityCode_verify_success";
    public static final String By_SecurityCode_verify_fail = ShopPresenter.class.getName()
            + "_By_SecurityCode_verify_fail";

    public ShopPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void login(String nickname, String openSid, String openId, String avatarUrl, String topAccessToken) {
        IShoping shoping = new ShopResponse(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(By_UserTbAccount_registerTb_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(By_UserTbAccount_registerTb_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                });
        shoping.login(nickname, openSid, openId, avatarUrl, topAccessToken);
    }

    @Override
    public void sendMsg(String codeType, String mobile,String send_type,String expire_time,String country) {
        IShoping shoping = new ShopResponse(
                new ICompleteListener() {
                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(By_SecurityCode_send_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(By_SecurityCode_send_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                });
        shoping.sendMsg(codeType, mobile,send_type,expire_time,country);
    }

    @Override
    public void checkMsg(String codeType, String accepter, String country, String code) {
        IShoping shoping = new ShopResponse(
                new ICompleteListener() {
                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(By_SecurityCode_verify_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(By_SecurityCode_verify_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                });
        shoping.checkMsg(codeType,accepter,country,code);
    }

    @Override
    public void bindPhone(String country, String code, String inviter, String mobile) {

    }
}
